package individuals;

import java.util.Random;

import main.Function;

public class Individual implements Comparable{

	private Double gen;
	private Double aptitud;
	private static Function func;
	private static Random randGen;
	
	public Individual() {
		this.gen = randGen.nextDouble()*6;
		if(randGen.nextBoolean()){
			this.gen = -this.gen;
		}
		
		this.aptitud = func.evaluate(this.gen);
	}
		
	public Individual(Double gen, Double aptitud) {
		super();
		this.gen = gen;
		this.aptitud = aptitud;
	}
	
	public Individual(Double gen) {
		super();
		this.gen = gen;
		this.aptitud = func.evaluate(this.gen);
	}
	
	public Double getGen() {
		return gen;
	}
	public void setGen(Double gen) {
		this.gen = gen;
	}
	public Double getAptitud() {
		return aptitud;
	}
	public void setAptitud(Double aptitud) {
		this.aptitud = aptitud;
	}

	@Override
	public int compareTo(Object o) {
		Individual other = (Individual)o;
		/*Para que se ordene ascendentemente autom�ticamente*/
		return -aptitud.compareTo(other.getAptitud());
	}

	public static void setFunc(Function func) {
		Individual.func = func;
	}

	public static Function getFunc() {
		return func;
	}

	public static void setRand(Random randGen) {
		Individual.randGen = randGen;
		
	}
	
	
	
}
